package com.stu.stusystem.service.chat;

import com.stu.stusystem.common.ApiException;
import com.stu.stusystem.mapper.chat.ChatMapper;
import com.stu.stusystem.model.chat.ChatMsg;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Service;

/**
 * @author: cxt
 * @time: 2021/6/23
 */
@Service
public class ChatService {

    private ChatMapper chatMapper;

    @Async("getAsyncExecutor")
    public void addMsg(ChatMsg chatMsg) {
        if (chatMapper == null) {
            return;
        }
        int insert = this.chatMapper.addMsg(chatMsg);
        if (insert == 0) {
            throw new ApiException(ApiException.SAVE_FAIL);
        }
    }

    @Autowired
    public void setChatMapper(ChatMapper chatMapper) {
        this.chatMapper = chatMapper;
    }
}
